﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;
using Com.CMS263.Util;

namespace Com.CMS263.DAO
{
    public class CustomerListDAO : BaseService
    {
        /// <summary>
        /// 根据email查询实体
        /// </summary>
        /// <param name="UEmail"></param>
        /// <returns></returns>
        public int UserEmailIteration(string UEmail)
        {
            try
            {
                string hql = "from CustomerList where Email='" + UEmail + "'";
                return FindList<CustomerList>(hql, null, null, null).Count();
            }
            catch
            {

                return 0;
            }
        }
        /// <summary>
        /// 根据手机号查询实体
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public int UseruserNameIteration(string userName)
        {
            try
            {
                string hql = "from CustomerList where UserName='" + userName + "'";
                return FindList<CustomerList>(hql, null, null, null).Count();
            }
            catch
            {

                return 0;
            }
        }
        /// <summary>
        /// 根据手机号和密码查询
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        public CustomerList FindModelByuserNameAndPass(string userName, string pass)
        {
            try
            {
                string pa = StringUtil.Md5(pass);
                string hql = "from CustomerList where UserName='" + userName + "' and UserPass='" + pa + "'";
                return FindList<CustomerList>(hql, null, null, null)[0];
            }
            catch
            {

                return null;
            }
        }
        /// <summary>
        /// 根据用户名查询
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        public CustomerList FindModelByuserName(string userName)
        {
            try
            {

                string hql = "from CustomerList where UserName='" + userName+"'";
                return FindList<CustomerList>(hql, null, null, null)[0];
            }
            catch
            {

                return null;
            }
        }
        /// <summary>
        /// 根据手机号和邮箱查询
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public CustomerList FindModelByuserNameAndEmail(string userName, string email)
        {
            try
            {
                string hql = "from CustomerList where UserName='" + userName + "' and UserEmail='" + email + "'";
                return FindList<CustomerList>(hql, null, null, null)[0];
            }
            catch
            {

                return null;
            }
        }

        public IList<CustomerList> FindList(string username, int page, int pageSize)
        {
            string hql = "from CustomerList where UserName like '%" + username + "%'";
            return FindList<CustomerList>(hql, null, pageSize * (page - 1), pageSize);
        }

        public int GetCount(string username)
        {
            try
            {
                string hql = "from CustomerList where UserName like '%" + username + "%'";
                return FindList<CustomerList>(hql, null, null, null).Count();
            }
            catch
            {

                return 0;
            }
        }
    }
}
